+2007-11-13 Øyvind Kolås <pippin@gimp.org>
+
+ * babl/babl-fish.c: (go_fishing): optimized fishing when looking
+ up existing fish (should perhaps be moved to lists going from given
+ formats, similar to how conversions are added there instead.) Made
+ go_fishing accept BABL_FISH_REFERENCE when source and desintation
+ formats are equal.
+ (babl_fish_process): removed most of the need for BablImage for
+ linear buffers, do a memcpy when source and destination formats
+ are equal (and we're a BABL_FISH_REFERENCE).
+ * babl/babl-db.[ch]: moved the BablDb struct out into public to
+ allow faster iteration through it.
+
2007-11-11 Øyvind Kolås <pippin@gimp.org>
* Modified copyright statement to refer to an URL instead of a civic
return db;
}
-typedef struct BablFishingData
-{
- Babl *source;
- Babl *destination;
- Babl *ret;
-} BablFishingData;
-
-static int
-fishing_result_examine (Babl *babl,
- void *void_data)
-{
- BablFishingData *data = void_data;
-
- if ((void *) data->source == (void *) babl->fish.source &&
- (void *) data->destination == (void *) babl->fish.destination)
- {
- data->ret = babl;
- /* we do not return BABL_FISH_REFERENCE's since those might exist
- * even before a valid BABL_FISH_PATH has been constructed for a
- * given conversion.
- */
- if (data->ret->class_type == BABL_FISH_REFERENCE)
- return 0;
- return 1; /* stop iterating */
- }
- return 0; /* continue iterating */
-}
-
-static Babl *
+static inline Babl *
go_fishing (Babl *source,
Babl *destination)
{
- {
- BablFishingData data;
+ BablDb *db = babl_fish_db ();
+ int i;
- data.source = source;
- data.destination = destination;
- data.ret = NULL;
-
- babl_db_each (db, fishing_result_examine, &data);
- return data.ret;
- }
+ for (i=0; i<db->count; i++)
+ {
+ Babl *item = db->items[i];
+ if ((void *) source == (void *) item->fish.source &&
+ (void *) destination == (void *) item->fish.destination &&
+ (item->class_type != BABL_FISH_REFERENCE ||
+ source == destination)
+ )
+ {
+ return item;
+ }
+ }
+ return NULL;
}
Babl *
return NULL;
}
- if(1){
+ {
Babl *lucky;
lucky = go_fishing (source_format, destination_format);
if (lucky)
void *destination,
long n)
{
- BablImage *source_image = NULL;
- BablImage *destination_image = NULL;
long ret = 0;
switch (babl->class_type)
case BABL_FISH_REFERENCE:
case BABL_FISH_SIMPLE:
case BABL_FISH_PATH:
-
-#if 0
- if (BABL_IS_BABL (source))
- source_image = source;
-#endif
- if (!source_image)
- source_image = (BablImage *) babl_image_from_linear (
- source, (Babl *) babl->fish.source);
-#if 0
- if (BABL_IS_BABL (destination))
- destination_image = destination;
-#endif
- if (!destination_image)
- destination_image = (BablImage *) babl_image_from_linear (
- destination, (Babl *) babl->fish.destination);
-
if (babl->class_type == BABL_FISH_REFERENCE)
{
- ret = babl_fish_reference_process (babl, source, destination, n);
+ if (babl->fish.source == babl->fish.destination)
+ { /* XXX: we're assuming linear buffers */
+ memcpy (source, destination, n * babl->fish.source->format.bytes_per_pixel);
+ ret = n;
+ }
+ else
+ {
+ ret = babl_fish_reference_process (babl, source, destination, n);
+ }
}
else if (babl->class_type == BABL_FISH_PATH)
{
}
else
{
- ret = babl_conversion_process (BABL (babl->fish_simple.conversion),
- (char *) source_image, (char *) destination_image, n);
+ babl_assert (0);
}
}
-
- babl_free (source_image);
- babl_free (destination_image);
break;
-
default:
babl_log ("NYI");
ret = -1;